import * as echarts from '../../plugin/ec-canvas/echarts';
// pages/login/login.js
//获取应用实例
const app = getApp()
const util = require('../../../utils/util.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    enter:'',
    grade:'',
    loadding: 0 ,
    currentTab : 0
  },
  onLoad: function(options) {
    console.log("enter",wx.getStorageSync('enter'))
    console.log("grade",options.grade)
    if(options.grade!=undefined && options.grade!=null){
      wx.setStorageSync('grade', options.grade)
      this.setData({
        enter : wx.getStorageSync('enter'),
        grade : options.grade
      })
    }
    let timeAfter  = util.formatTime(new Date())
    this.setData({
      curTime : timeAfter,
      grade : wx.getStorageSync('grade'),
      loadding: 1
    })
    let timePre = util.formatTime2(new Date()) +" 00:00:00"
    let inStudentNameList = []
    let outStudentNameList = []
    let unRecordList =[]
    let inCount = 0
    let outCount = 0
    let unRecord = 0
    wx.request({
      url: app.baseUrl +"/WeChat/schoolMangement/getInOutRecordDetailStudentName",
      method: 'POST',
      header:{
        "content-type":"application/json"
      },
      data: JSON.stringify({
        department: app.globalData.departmentId,
        timePre : timePre ,
        timeAfter : timeAfter,
        grade: wx.getStorageSync('grade')
      }),
      dataType: 'json',
      success: res => {
        console.log("InOutRecordStudentNameList", res.data)
        res.data.InOutRecordStudentNameList.forEach((item, index) => {
          if (item.status == 'in') {
              inStudentNameList.push(
                  item.name
              )
              inCount = inStudentNameList.length
          } else if(item.status == 'out'){
              outStudentNameList.push(
                  item.name
              )
              outCount = outStudentNameList.length
          }else if(item.status == 'no'){
              unRecordList.push(
                  item.name
              )
              unRecord = unRecordList.length
          }
        })
        console.log("inStudentNameList",inStudentNameList)
        this.setData({
          inStudentNameList: inStudentNameList,
          inCount: inCount,
          outStudentNameList: outStudentNameList,
          outCount: outCount,
          unRecordList:unRecordList,
          unRecord:unRecord,
          loadding: 0
        })
      }
    })
    
  },
    /**
   * 点击tab切换
   */
  swichNav:function(e){
    this.setData({
      currentTab: e.currentTarget.dataset.current
    })
    if (this.data.currentTab == 0) {
    } else if (this.data.currentTab == 1) {
    } else if (this.data.currentTab == 2) { 
    }
  },
   /**
   * 滑动切换tab
   */
  bindChange: util.throttle(function (e) {
    this.setData({
      currentTab: e.detail.current
    })
    if (this.data.currentTab == 0) {
    } else if (this.data.currentTab == 1) {

    } else if (this.data.currentTab == 2) {

    }
  })
})

